package com.wenx.restcamel;

import com.wenx.camel.reviveProcess;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import java.io.IOException;

public class AppJetty extends RouteBuilder {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new AppJetty());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    public void configure() throws Exception {
        from("jetty:http://localhost:8080/camel?sessionSupport=true")
                .removeHeaders("CamelHttp*")
                .process(new reviveProcess())
                .to("file:d:/log?fileName=es1.html");
                //.to("stream:out");

//        from("timer:foo?repeatCount=1")
//                .to("jetty:http://blog.csdn.net/mendeliangyang/article/details/47025517")
//                .removeHeaders("CamelHttp*")
//               // .process(new reviveProcess())
//                .to("file:d:/log?fileName=es1.html");
//                .process(new Processor() {
//                    public void process(Exchange e) throws IOException {
//                        System.out.println("Received exchange: " + e.getIn());
//                        System.out.println(e.getIn().getBody(String.class));
//                    }
//                });
    }
}
